Skip to content

Close pull requests opened from a fork - #205

Merged
ale210 merged 2 commits into
masterfrom
close-fork-prs-action
Aug 29, 2026
Merged

ale210 merged 2 commits into
masterfrom
close-fork-prs-action

Conversation

@ale210

@ale210 ale210 commented Aug 29, 2026

Copy link
Copy Markdown
Member

Adds .github/workflows/close-fork-prs.yml, which closes pull requests opened from a fork and explains to the author what to do instead. Contributors have started picking up tickets without joining the DevOps group, and a fork PR on incubator or devops-security can never be merged — terraform plan can't run, so there is nothing to review. Leaving those PRs open just wastes the contributor's time.

The same file goes in all three CoP repos (devops, devops-security, incubator), byte-identical.

Two ways it runs:

  • Automatically on pull_request_target (opened, reopened) — closes the PR straight away with a comment.
  • Manually from the Actions tab (workflow_dispatch) — sweeps every open pull request in the repo and closes the ones from forks. Defaults to a dry run that lists what it would close and closes nothing, so the destructive version is always a deliberate choice.

The check is one expression: a PR is from a fork exactly when head.repo.full_name != github.repository.

Why pull_request_target and not pull_request: a pull_request run triggered from a fork gets a read-only GITHUB_TOKEN and cannot close or comment on anything — the same restriction that makes fork PRs unmergeable in the first place. pull_request_target runs with the base repo's token.

Security. pull_request_target is the trigger with the privilege-escalation footgun, so the workflow deliberately: checks out nothing, builds nothing, uses no third-party actions at all (just the preinstalled gh CLI), and passes every PR-controlled value through the environment rather than interpolating it into a shell command. There is no path for code or text from the pull request to be executed. Permissions are contents: read and pull-requests: write.

No actions to pin means nothing here to version-bump later.

Note on sequencing: workflow_dispatch only appears in the Actions tab once this is on the default branch — GitHub reads both triggers from there. The comment it posts links to the "Do not fork the repository" section added in #204, so that one should merge first.

@ale210
ale210 merged commit 4fdf538 into master Aug 29, 2026
@ale210 ale210 mentioned this pull request Sep 4, 2026
7 tasks done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant